<template>
  <div class="list-page">
    <tool-bar nav="" title="Es数据连接">
      <el-button @click="add_click()">添加</el-button>
    </tool-bar>
    <my-list
        ref="list"
        url="/dev/es-connection/list"
        @param="preload"
        @loaded="procData"
        :page-size="10"
        :query="$data.query"
        delete-url="/dev/es-connection/delete/{id}"
    >
      <el-table-column label="名称" align="center">
        <template v-slot="scope">
          <div class="link" @click="edit_click(scope.row)">{{ scope.row.name }}</div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="Ip" prop="host"></el-table-column>
      <el-table-column align="center" label="端口" prop="port"></el-table-column>
      <el-table-column align="center" label="用户名" prop="userName"></el-table-column>
      <el-table-column align="center" label="code" prop="code"></el-table-column>
<!--      <el-table-column label="操作" align="center" width="100">-->
<!--        <template v-slot="scope">-->
<!--          <el-button plain round @click="app_click(scope.row)" size="small">-->
<!--            app-api-->
<!--          </el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="操作" align="center" width="200">
        <template v-slot="scope">
          <el-button plain round @click="esql_click(scope.row)" size="small">
            es|ql
          </el-button>
          <el-button plain round @click="exp_click(scope.row)" size="small">
            导出
          </el-button>
          <el-button plain round @click="imp_click(scope.row)" size="small">
            导入
          </el-button>
        </template>
      </el-table-column>

      <template #query="scope">
        <kv label="名称">
          <el-input v-model="scope.query.name"></el-input>
        </kv>
      </template>
    </my-list>
  </div>
</template>

<script setup>
/**
 * Created by CodeGenerator at 2025-08-31 02:38:43
 */


//定义 vue2的this,当前组件
let $self = getCurrentInstance();

//定义 $attrs
let $attrs = useAttrs()


//定义事件
let $emit = defineEmits(["update:modelValue", "loaded"]);

//定义属性
var $props = defineProps({});

//定义data
let $data = reactive({
  //默认查询条件,默认存储
  query: {},
})

/**
 * 添加查询参数，修改分页参数等。
 * @param param
 */
const preload = (param) => {
  //param.type = this.$route.params.type
}

/**
 * 处理列表的数据
 * @param res
 */
const procData = (res) => {
  res.data.data.forEach(it => {
    //如果是组合实体，设置 it.id=...
  });
}

const list = ref();

/**
 * 查询列表
 * @param pageNumber
 */
const loadData = (pageNumber) => {
  list.value.loadData(pageNumber);
}

const app_click = (row) => {
  let rowId = row.id, rowName = row.name;
  jv.$router.push("/es/file-log-list/" + rowId + "?title=" + rowName)
}

const esql_click = (row) => {
  let rowId = row.id, rowName = row.name;
  jv.$router.push("/ops/es-tool/esql/" + rowId)
}
const exp_click = (row) => {
  let rowId = row.id, rowName = row.name;
  jv.$router.push("/ops/es-tool/export/" + rowId)
}
const imp_click = (row) => {
  let rowId = row.id, rowName = row.name;
  jv.$router.push("/ops/es-tool/import/" + rowId)
}

const add_click = () => {
  jv.$router.push("/dev/es-connection/add")
}

const edit_click = (row) => {
  //记录上次点击行
  let rowId = row.id;
  list.value.setLastRow(row);
  jv.$router.push("/dev/es-connection/edit/" + rowId)
}

// const delete_click = async (row) => {
//     let rowId = row.id,rowName = row.name;
//     await jv.confirm('确认删除 ' + rowName + ' 吗？');
//
//     let res = await jv.$http.post("/dev/es-connection/delete/" + rowId)
//     loadData();
// }


</script>

<style scoped lang="scss">
</style>
